#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=2e4+10,MAXM=1e5+10;
int n,m,fa[2*MAXN];
struct edge
{
	int u,v,val;
	bool operator<(const edge b)const
	{
		return val>b.val;
	}
}e[MAXM];
int getfa(int x)
{
	return x==fa[x]?x:fa[x]=getfa(fa[x]);
}
int main()
{
	n=read();m=read();
	for(int i=1;i<=m;++i)
		e[i].u=read(),e[i].v=read(),e[i].val=read();
	sort(e+1,e+1+m);
	for(int i=1;i<=2*n;++i)
		fa[i]=i;
	for(int i=1;i<=m;++i)
	{
		int x=getfa(e[i].u),y=getfa(e[i].v);
		if(x==y)
		{
			printf("%d\n",e[i].val);
			return 0;
		}
		fa[x]=getfa(e[i].v+n);
		fa[y]=getfa(e[i].u+n);
	}
	puts("0");
	return 0;
}
